<template>
  <div>
    <el-card class="box-card">
      <el-form
        ref="elForm"
        :model="formData"
        :rules="rules"
        size="medium"
        label-width="100px"
        :label-position="labelPosition"
      >
        <el-row :gutter="15">
          <el-col :span="7">
            <el-form-item label-width="140px" label="居住情况" prop="livingCondition">
              <el-select
                v-model="formData.livingCondition"
                placeholder="请选择居住情况"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in dict.type.user_reside_circumstance"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label-width="140px" label="养老方式" prop="oldAgeCare">
              <el-select
                v-model="formData.oldAgeCare"
                placeholder="请选择养老方式"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in dict.type.user_reside_pension"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label-width="140px" label="燃料类型" prop="fuelType">
              <el-select
                v-model="formData.fuelType"
                placeholder="请选择燃料类型"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in dict.type.user_reside_fuel"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="7">
            <el-form-item label-width="140px" label="饮水类型" prop="drinkingType">
              <el-select
                v-model="formData.drinkingType"
                placeholder="请选择饮水类型"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in dict.type.user_reside_water"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label-width="140px" label="老人分类" prop="oldManType">
              <el-select
                v-model="formData.oldManType"
                placeholder="请选择老人分类"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in dict.type.user_reside_oldman"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label-width="140px" label="厨房排风设施" prop="kitchenExhaust">
              <el-select
                v-model="formData.kitchenExhaust"
                placeholder="请选择厨房排风设施"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in dict.type.user_reside_kitchen"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="7">
            <el-form-item label-width="140px" label="宠物" prop="pet">
              <el-select
                v-model="formData.pet"
                placeholder="请选择宠物"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in dict.type.user_reside_pet"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label-width="140px" label="补偿" prop="compensation">
              <el-select
                v-model="formData.compensation"
                placeholder="请选择补偿"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in dict.type.user_subsidy_type"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label-width="140px" label="政府补助" prop="publicSubsidy">
              <el-select
                v-model="formData.publicSubsidy"
                placeholder="请选择政府补助"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in dict.type.uesr_subsidy_money"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="7">
            <el-form-item
              label-width="140px"
              label="政府补助标准"
              prop="publicSubsidyCriterion"
            >
              <el-select
                v-model="formData.publicSubsidyCriterion"
                placeholder="请选择政府补助标准"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in dict.type.user_subsidy_standard"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label-width="140px" label="生活需求" prop="lifeNeed">
              <el-select
                v-model="formData.lifeNeed"
                placeholder="请选择生活需求"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in dict.type.user_demand_life"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label-width="140px" label="家政需求" prop="homemakingNeed">
              <el-select
                v-model="formData.homemakingNeed"
                placeholder="请选择家政需求"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in dict.type.user_demand_housekeeping"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15">
          <el-col :span="7">
            <el-form-item
              label-width="140px"
              label="医疗需求"
              prop="medicalTreatmentNeed"
            >
              <el-select
                v-model="formData.medicalTreatmentNeed"
                placeholder="请选择医疗需求"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in dict.type.user_demand_medical"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label-width="140px" label="精神需求" prop="spiritNeed">
              <el-select
                v-model="formData.spiritNeed"
                placeholder="请选择精神需求"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in dict.type.user_demand_spirit"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item
              label-width="140px"
              label="是否接受电话关怀"
              prop="phoneCondoleNeed"
            >
              <el-select
                v-model="formData.phoneCondoleNeed"
                placeholder="请选择是否接受电话关怀"
                clearable
                :style="{ width: '100%' }"
              >
                <el-option
                  v-for="(item, index) in dict.type.iot_yes_no"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="15"> </el-row>
        <el-form-item size="large">
          <el-button type="primary" @click="submitForm">提交</el-button>
          <el-button @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
import { addDwell, updateDwell, getDwell } from "@/api/cluster/dwell";

export default {
  dicts: [
    "user_reside_circumstance",
    "user_reside_pension",
    "user_reside_fuel",
    "user_reside_water",
    "user_reside_oldman",
    "user_reside_kitchen",
    "user_reside_pet",
    "user_subsidy_type",
    "uesr_subsidy_money",
    "user_subsidy_standard",
    "user_demand_life",
    "user_demand_housekeeping",
    "user_demand_medical",
    "user_demand_spirit",
    "iot_is_enable",
    "phoneCondoleNeed",
    "iot_yes_no"
  ],
  data() {
    return {
      labelPosition: "top",
      formData: {
        livingCondition: undefined,
        oldAgeCare: undefined,
        fuelType: undefined,
        drinkingType: undefined,
        oldManType: undefined,
        kitchenExhaust: undefined,
        pet: undefined,
        compensation: undefined,
        publicSubsidy: undefined,
        publicSubsidyCriterion: undefined,
        lifeNeed: undefined,
        homemakingNeed: undefined,
        medicalTreatmentNeed: undefined,
        spiritNeed: undefined,
        phoneCondoleNeed:undefined
      },
      rules: {
        livingCondition: [
          {
            required: true,
            message: "请选择居住情况",
            trigger: "change",
          },
        ],
        oldAgeCare: [
          {
            required: true,
            message: "请选择养老方式",
            trigger: "change",
          },
        ],
        fuelType: [
          {
            required: true,
            message: "请选择燃料类型",
            trigger: "change",
          },
        ],
        drinkingType: [
          {
            required: true,
            message: "请选择饮水类型",
            trigger: "change",
          },
        ],
        oldManType: [
          {
            required: true,
            message: "请选择老人分类",
            trigger: "change",
          },
        ],
        kitchenExhaust: [
          {
            required: true,
            message: "请选择厨房排风设施",
            trigger: "change",
          },
        ],
        pet: [
          {
            required: true,
            message: "请选择宠物",
            trigger: "change",
          },
        ],
        compensation: [
          {
            required: true,
            message: "请选择补偿",
            trigger: "change",
          },
        ],
        publicSubsidy: [
          {
            required: true,
            message: "请选择政府补助",
            trigger: "change",
          },
        ],
        publicSubsidyCriterion: [
          {
            required: true,
            message: "请选择政府补助标准",
            trigger: "change",
          },
        ],
        lifeNeed: [
          {
            required: true,
            message: "请选择生活需求",
            trigger: "change",
          },
        ],
        homemakingNeed: [
          {
            required: true,
            message: "请选择家政需求",
            trigger: "change",
          },
        ],
        medicalTreatmentNeed: [
          {
            required: true,
            message: "请选择医疗需求",
            trigger: "change",
          },
        ],
        spiritNeed: [
          {
            required: true,
            message: "请选择精神需求",
            trigger: "change",
          },
        ],
        phoneCondoleNeed: [
          {
            required: true,
            message: "请选择是否接受电话关怀",
            trigger: "change",
          },
        ],
      },
    };
  },
  computed: {},
  watch: {},
  created() {
    this.getList();
  },
  mounted() {},
  methods: {
    getList() {
      getDwell(this.$route.query.id).then((res) => {
        if (res.data) {
          this.formData = res.data;
        this.formData.livingCondition= String(res.data.livingCondition)
        this.formData.oldAgeCare= String(res.data.oldAgeCare)
        this.formData.fuelType= String(res.data.fuelType)
        this.formData.drinkingType= String(res.data.drinkingType)
        this.formData.oldManType= String(res.data.oldManType)
        this.formData.kitchenExhaust= String(res.data.kitchenExhaust)
        this.formData.pet= String(res.data.pet)
        this.formData.compensation= String(res.data.compensation)
        this.formData.publicSubsidy= String(res.data.publicSubsidy)
        this.formData.publicSubsidyCriterion= String(res.data.publicSubsidyCriterion)
        this.formData.lifeNeed= String(res.data.lifeNeed)
        this.formData.homemakingNeed= String(res.data.homemakingNeed)
        this.formData.medicalTreatmentNeed= String(res.data.medicalTreatmentNeed)
        this.formData.spiritNeed= String(res.data.spiritNeed)
        this.formData.phoneCondoleNeed= String(res.data.phoneCondoleNeed)
        }
      });
    },
    submitForm() {
      this.formData.oldManId=this.$route.query.id
      this.$refs["elForm"].validate((valid) => {
        // TODO 提交表单
        if (valid) {
          if (this.formData.id) {
            updateDwell(this.formData).then((res) => {
              this.$router.go(-1)
            });
          } else {
            addDwell(this.formData).then((res) => {
              this.$router.go(-1)
            });
          }
        }
      });
    },
    resetForm() {
      this.$refs["elForm"].resetFields();
    },
  },
};
</script>
<style></style>
